<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的文章</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    
    <link rel="stylesheet" href="__HOME__/css/weui.css">
    <link rel="stylesheet" href="__HOME__/css/jquery-weui.css">
    <link rel="stylesheet" href="__HOME__/css/style.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_729135_t2loq20h12.css">
    
    <script src="__HOME__/js/jquery.min.js"></script>
    <script src="__HOME__/js/jquery-weui.min.js"></script>
    <script src="__HOME__/js/vue.js"></script>
   
    <style>
        .weui-panel:after {
            bottom: 0;
            border-bottom: 0px solid #e5e5e5;
            -webkit-transform-origin: 0 100%;
            transform-origin: 0 100%;
            -webkit-transform: scaleY(.5);
            transform: scaleY(.5);
        }
        .weui-panel:before {
            top: 0;
            border-top: 0px solid #e5e5e5;
            -webkit-transform-origin: 0 0;
            transform-origin: 0 0;
            -webkit-transform: scaleY(.5);
            transform: scaleY(.5);
        }
    </style>
</head>
<body class="back1">
<div id="app">
    <div class="index-top-fix">
        <a href="{:url('store/teacher.index/mycenter')}" class="iconfont icon-left- left"></a>
        <p class="title">我的文章</p>
    </div>
    <div class="mt50"></div>

    <div class="weui-panel weui-panel_access" style="background-color: #f3f3f3" >
        <div class="weui-panel__bd" style="background-color: #f3f3f3">
            <a href="javascript:void(0);" style="background-color: #fff" class="weui-media-box weui-media-box_appmsg" v-for="(item,index) in items"  :data_id="item.id">
                <div class="weui-media-box__hd" style="height: 78px">
                    <img class="weui-media-box__thumb" :src="item.picture" style="height: 60px" >
                </div>
                <div class="weui-media-box__bd">
                    <span class="weui-media-box__title" style="float: left;display: block;width:80%;overflow: hidden; text-overflow: ellipsis; -o-text-overflow: ellipsis;white-space:nowrap;">{{item.title}}</span>
                    <span v-if="item.status==0" style="float: right;color: orangered">审核中</span>
                    <span v-if="item.status==1" style="float: right;color: orangered">已审核</span>
                    <span v-if="item.status==2" style="float: right;color: orangered">已拒绝</span>
                    <div class="weui-media-box__desc" style="padding-top: 5px;color: rgb(86, 126, 184);clear: both"><span>作者：</span><span>{{item.author}}</span></div>
                    <div class="weui-media-box__desc" style="padding-top: 5px;color: rgb(86, 126, 184);clear: both"><span>类别：</span><span>{{item.sort}}</span></div>
                    <div class="weui-media-box__desc" style="float: right;border: 1px solid rgb(86, 126, 184);">
                       <span style="padding: 5px 5px;color:rgb(86, 126, 184)" :data_id="item.id" :data_index="index"  onclick="del(this)">删除</span>
                    </div>
                    <div v-if="item.edit==0" class="weui-media-box__desc" style="float: right;border: 1px solid rgb(86, 126, 184);margin-right: 5px">
                         <span style="padding: 5px 5px;color:rgb(86, 126, 184)" :data_id="item.id" :data_index="index"  onclick="edt(this)">编辑</span>
                    </div>
                </div>
            </a>
            <!--滚动加载-->
            <div class="weui-loadmore" v-if="is_loading" style="padding-bottom:20px;height:20px;">
                <i class="weui-loading"></i>
                <span class="weui-loadmore__tips">正在加载</span>
            </div>

            <div class="weui-cells__title" v-if="is_none" style="text-align: center;margin-bottom: 20px">无更多数据</div>
        </div>
    </div>

</div>
</body>
<script>
    <!--滚动加载-->
    var app = new Vue({
        el: '#app',
        data: {
            //初始化
            items: [],
            is_loading: false,
            is_none: false,
            cur_page: 1,
            limit: 5,
        },
    });
    //滚动加载更多
    $(function () {
        //进入加载页面
        loadlist();
    });
    $('.back1').infinite().on('infinite', function () {
        console.log("加载");
        loadlist();
    });
    //ajax加载数据
    function loadlist(flag) {
        console.log(flag);
        if (!app.is_loading && app.is_none != true) {
            app.is_loading = true;
            $.post('{:url("/store/teacher.article/loaddata")}', {page: app.cur_page, limit: app.limit}, function (res) {
                console.log(res);

                app.is_loading = false;
                if (res.count > 0) {
                    $('.weui-panel__bd').show();
                    if(app.cur_page==1){
                        app.items=res.data;
                    }else {
                        for (var index in res.data) {
                            app.items.push(res.data[index]);
                        }
                    }


                    app.cur_page++;


                } else {
                    app.is_none = true;
                }

            });
        }

    }
    // 删除
    function del(that) {
        var data_id = $(that).attr('data_id');
        var data_index= $(that).attr('data_index');
        $.confirm("您确定删除吗?", "确定删除?", function () {
            $.post('{:url("del")}',{id:data_id},
                function (res) {
                    if(res.code==1){
                        app.items.splice(data_index,1);
                        $.toast(res.msg);
                        // 定时跳转
                        // setTimeout(function(){
                        //     location.href="{:url('store/teacher.index/list_article')}";
                        //     console.log("success");
                        // },1500);
                    }
                    else{
                        $.toast(res.msg);
                        return false;
                    }
                });
        }, function () {
            //取消操作
        });

    }

    // 编辑
    function edt(that) {
        var data_id=$(that).attr('data_id');
        var data_index= $(that).attr('data_index');
        $.confirm("每篇文章只可编辑一次，确认编辑?","确认编辑?",function () {
            var s="{:url('edit_article')}?id="+data_id;
            location.href=s;
        },function () {
            // 取消操作
        })
    }
</script>
</html>

